package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.ClanAllianceTable;
import com.lineage.server.datatables.storage.ClanAllianceStorage;
import com.lineage.server.model.L1Alliance;
import com.lineage.server.model.L1Clan;
import java.util.ArrayList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ClanAllianceReading {
  private static ClanAllianceReading _instance;
  
  private final Lock _lock = new ReentrantLock(true);
  
  private final ClanAllianceStorage _storage = (ClanAllianceStorage)new ClanAllianceTable();
  
  public static ClanAllianceReading get() {
    if (_instance == null)
      _instance = new ClanAllianceReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void insertAlliance(L1Alliance alliance) {
    this._lock.lock();
    try {
      this._storage.insertAlliance(alliance);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void updateAlliance(int order_id, ArrayList<L1Clan> totalList) {
    this._lock.lock();
    try {
      this._storage.updateAlliance(order_id, totalList);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void deleteAlliance(int order_id) {
    this._lock.lock();
    try {
      this._storage.deleteAlliance(order_id);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public L1Alliance getAlliance(int clan_id) {
    L1Alliance tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getAlliance(clan_id);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
}
